package cloud.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.google.appengine.api.mail.*;
import com.google.appengine.api.mail.MailServicePb.MailMessage;

public class MailQueue  extends HttpServlet {
	
	/**
	 * Affichage de la page.
	 */
	public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException{

	}

	
	/**
	 * Traitement de la page.
	 */
	public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException{
		
		String msgBody = "User " + request.getParameter("userName") + " has posted a new review on the app";
		
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

       

        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("thesnake973@gmail.com", "Admin"));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress("thesnake973@gmail.com", "Mr. User"));
            msg.setSubject("A new review has been posted");
            msg.setText(msgBody);
            Transport.send(msg);

        } catch (AddressException e) {
            // ...
        } catch (MessagingException e) {
            // ...
        }
	}
}
